package com.cykj.user.controller;

import com.cykj.common.core.utils.poi.ExcelUtil;
import com.cykj.common.core.web.controller.BaseController;
import com.cykj.common.core.web.domain.AjaxResult;
import com.cykj.common.core.web.page.TableDataInfo;
import com.cykj.common.log.annotation.Log;
import com.cykj.common.log.enums.BusinessType;
import com.cykj.common.security.annotation.RequiresPermissions;
import com.cykj.user.domain.CtBan;
import com.cykj.user.service.ICtBanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
 * @BelongsProject: Cykj-Order-System
 * @BelongsPackage: com.cykj.user.controller
 * @Author: 阿强
 * @CreateTime: 2025-08-20 17:30
 * @Description: TODO
 * @Version: 1.0
 */

/**封禁原因Controller*/
@RestController
@RequestMapping("/ban")
public class CtBanController extends BaseController
{
    @Autowired
    private ICtBanService ctBanService;

    /**
     * 查询封禁原因列表
     */
    @RequiresPermissions("system:ban:list")
    @GetMapping("/list")
    public TableDataInfo list(CtBan ctBan)
    {
        startPage();
        List<CtBan> list = ctBanService.selectCtBanList(ctBan);
        return getDataTable(list);
    }

    /**导出封禁原因列表*/
    @RequiresPermissions("system:ban:export")
    @Log(title = "封禁原因", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CtBan ctBan)
    {
        List<CtBan> list = ctBanService.selectCtBanList(ctBan);
        ExcelUtil<CtBan> util = new ExcelUtil<CtBan>(CtBan.class);
        util.exportExcel(response, list, "封禁原因数据");
    }

    /**
     * 获取封禁原因详细信息
     */
    @RequiresPermissions("system:ban:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ctBanService.selectCtBanById(id));
    }

    /**
     * 新增封禁原因
     */
    @RequiresPermissions("system:ban:add")
    @Log(title = "封禁原因", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CtBan ctBan)
    {
        return toAjax(ctBanService.insertCtBan(ctBan));
    }

    /**
     * 修改封禁原因
     */
    @RequiresPermissions("system:ban:edit")
    @Log(title = "封禁原因", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CtBan ctBan)
    {
        return toAjax(ctBanService.updateCtBan(ctBan));
    }

    /**
     * 删除封禁原因
     */
    @RequiresPermissions("system:ban:remove")
    @Log(title = "封禁原因", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ctBanService.deleteCtBanByIds(ids));
    }
}
